package code.rocky.chapter07;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class SubjectHandler implements InvocationHandler {

    private Subject subject;

    public SubjectHandler(Subject _subject) {
        subject = _subject;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        // 预处理
        System.out.println("预处理");
        // 直接被调用代理类的方法
        Object obj = method.invoke(subject, args);
        //后处理
        System.out.println("后处理");
        return obj;
    }
}
